package departmentservice

import (
	"fmt"
	"yunj/pkg/yunj/app/data"
	"yunj/pkg/yunj/app/enum/admin/departmentenum"
	"yunj/pkg/yunj/core/builder/builderdto"
	"yunj/pkg/yunj/util"
)

// 获取正常部门枚举选项
func GetNormalTableColOptions() (options []builderdto.TableColOption) {
	departments := data.Department.GetNormalDepartments()
	options = make([]builderdto.TableColOption, 0, len(departments))
	for _, department := range departments {
		options = append(options, builderdto.TableColOption{
			Value:     department.Id,
			Label:     fmt.Sprintf("【%s】%s", departmentenum.TypeByValue(department.Type).GetDesc(), department.Name),
			FullLabel: department.FullName,
			BgColor:   util.RandomHexColor("#ffffff"),
		})
	}
	return
}

// 获取正常的表单选择树节点
func GetNormalFormTreeCheckNodes() (nodes []*builderdto.FormTreeCheckNode) {
	departments := data.Department.GetNormalDepartments()
	nodes = make([]*builderdto.FormTreeCheckNode, 0, len(departments))
	for _, department := range departments {
		node := &builderdto.FormTreeCheckNode{
			Id:   department.Id,
			Pid:  department.Pid,
			Name: fmt.Sprintf("【%s】%s", departmentenum.TypeByValue(department.Type).GetDesc(), department.Name),
		}
		nodes = append(nodes, node)
	}
	return
}
